package com.hcb.tonguetiphealth.manager;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;

import com.hcb.tonguetiphealth.model.Wine;

public class WineManager {
	public static boolean isGotBrad = false;
	public static boolean isGotType = false;
	public static boolean isGotPrice = false;
	private DBManager db;
	private String tableName;
	private List<Wine> list;
	private int flag;
	
	public WineManager(Activity ctx, int flag) {
		db = DBManager.getInstance(ctx);
		this.flag = flag;
		switch(flag) {
		case Wine.BRAND:
			tableName = DBManager.table_wineBrand;
			break;
		case Wine.PRICE:
			tableName = DBManager.table_winePrice;
			break;
		case Wine.TYPE:
			tableName = DBManager.table_wineType;
			break;
		case Wine.POPULARITY:
			break;
		}
	}
	/**
	 * 保存酒水品牌
	 * @param List<WineBrand>
	 * @return
	 */
	public void saveWine(List<Wine> list) {
		db.deleteAll(tableName);
		ContentValues values;
		for(Wine wine : list) {
			values = new ContentValues();
			values.put("strid", wine.getStrId());
			values.put("name", wine.getName());
			db.insert(tableName, values);
		}
		switch(flag) {
		case Wine.BRAND:
			isGotBrad = true;
			break;
		case Wine.PRICE:
			isGotPrice = true;
			break;
		case Wine.TYPE:
			isGotType = true;
			break;
		case Wine.POPULARITY:
			break;
		}
	}
	
	/**
	 * 获取酒水类型、品牌、价格
	 * @return
	 */
	public List<Wine> getWineList() {
		list = new ArrayList<Wine>();
		Wine wine = null;
		Cursor mCursor = db.getCursor(tableName);
		if (null != mCursor) {
			while(mCursor.moveToNext()) {
				wine = new Wine();
				wine.setId(mCursor.getInt(0));
				wine.setStrId(mCursor.getString(1));
				wine.setName(mCursor.getString(2));
				list.add(wine);
			}
			mCursor.close();
		}
		
		return list;
	}
}
